class Solution(object): def groupAnagrams(self, strs): """ :type strs: List[str] :rtype: List[List[str]] """ temp_dict = {} for word in strs: word_key = "".join(sorted(word)) if word_key not in temp_dict: temp_dict[word_key] = [word] else: temp_dict[word_key].append(word) print temp_dict result = [] for value in temp_dict.values(): result += [value] return result